<?php

/**
 * This is the model class for table "{{representante_legal}}".
 *
 * The followings are the available columns in table '{{representante_legal}}':
 * @property integer $ID_REPRESENTANTE_LEGAL
 * @property string $NOMBRE
 * @property string $APP
 * @property string $APM
 * @property string $FEC_NAC
 * @property string $CURP
 * @property string $RFC
 * @property string $DOMICILIO
 * @property string $TELEFONO
 * @property string $CORREO_ELECTRONICO
 * @property integer $ACTIVO
 * @property string $NSS
 *
 * The followings are the available model relations:
 * @property Empresa[] $empresas
 */
class RepresentanteLegal extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return RepresentanteLegal the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{representante_legal}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ACTIVO', 'numerical', 'integerOnly'=>true),
			array('NOMBRE, APP, APM, TELEFONO', 'length', 'max'=>100),
			array('CURP', 'length', 'max'=>18),
			array('RFC', 'length', 'max'=>13),
			array('DOMICILIO, CORREO_ELECTRONICO', 'length', 'max'=>300),
			array('NSS', 'length', 'max'=>20),
			array('FEC_NAC', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID_REPRESENTANTE_LEGAL, NOMBRE, APP, APM, FEC_NAC, CURP, RFC, DOMICILIO, TELEFONO, CORREO_ELECTRONICO, ACTIVO, NSS', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'empresas' => array(self::HAS_MANY, 'Empresa', 'ID_REPRESENTANTE_LEGAL'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID_REPRESENTANTE_LEGAL' => 'Id Representante Legal',
			'NOMBRE' => 'Nombre',
			'APP' => 'App',
			'APM' => 'Apm',
			'FEC_NAC' => 'Fec Nac',
			'CURP' => 'Curp',
			'RFC' => 'Rfc',
			'DOMICILIO' => 'Domicilio',
			'TELEFONO' => 'Telefono',
			'CORREO_ELECTRONICO' => 'Correo Electronico',
			'ACTIVO' => 'Activo',
			'NSS' => 'Nss',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID_REPRESENTANTE_LEGAL',$this->ID_REPRESENTANTE_LEGAL);
		$criteria->compare('NOMBRE',$this->NOMBRE,true);
		$criteria->compare('APP',$this->APP,true);
		$criteria->compare('APM',$this->APM,true);
		$criteria->compare('FEC_NAC',$this->FEC_NAC,true);
		$criteria->compare('CURP',$this->CURP,true);
		$criteria->compare('RFC',$this->RFC,true);
		$criteria->compare('DOMICILIO',$this->DOMICILIO,true);
		$criteria->compare('TELEFONO',$this->TELEFONO,true);
		$criteria->compare('CORREO_ELECTRONICO',$this->CORREO_ELECTRONICO,true);
		$criteria->compare('ACTIVO',$this->ACTIVO);
		$criteria->compare('NSS',$this->NSS,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}